package com.hotel.BL;

import java.util.Date;

import com.EntityName;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.EntityNotFoundException;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

import data.SubFlexiblePackage;

public class SubFlexiblePackageLogic extends AbstractBL{
	public SubFlexiblePackage GetSubFlexiblePackage(long id) {
		Key key = KeyFactory.createKey(EntityName.SubFlexiblePackage, id);
		try {
			Entity lang = datastore.get(key);
			SubFlexiblePackage c = new SubFlexiblePackage();
			c.setEntity(lang);
			return c;
		} catch (EntityNotFoundException e) {
			return null;
		}
	}
	
	public SubFlexiblePackage AddSubFlexiblePackage(Date date,double extrabed,double pricepernight,
			double upchargeperperson,long adult,long child,boolean inclusiveBreakfast)
			throws EntityNotFoundException {
		SubFlexiblePackage t = new SubFlexiblePackage();
		t.setDate(date);
		t.setExtrabed(extrabed);
		t.setPricepernight(pricepernight);
		t.setUpchargeperperson(upchargeperperson);
		t.setAdult(adult);
		t.setChild(child);
		t.setInclusiveBreakfast(inclusiveBreakfast);
		
		Key k = datastore.put(t.getEntity());
		t.setId(k.getId());
		t.setKey(k);

		return t;
	}
	
	public SubFlexiblePackage EditSubFlexiblePackage(long id,Date date,double extrabed,double pricepernight,
			double upchargeperperson,long adult,long child,boolean inclusiveBreakfast)
			throws EntityNotFoundException {
		SubFlexiblePackage t = GetSubFlexiblePackage(id);
		t.setDate(date);
		t.setExtrabed(extrabed);
		t.setPricepernight(pricepernight);
		t.setUpchargeperperson(upchargeperperson);
		t.setAdult(adult);
		t.setChild(child);
		t.setInclusiveBreakfast(inclusiveBreakfast);
		
		Key k = datastore.put(t.getEntity());
		t.setId(k.getId());
		t.setKey(k);

		return t;
	}
}
